<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>已点餐项</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
    <header>
        <h1>已点餐项</h1>
    </header>
    <div class="menu-container">
        <h2>已点餐项列表</h2>
        <div id="ordered-menus">
            {% for order in orders %}
            <div class="ordered-menu-item" data-order-id="{{ order.order_id }}">
                <h3>{{ order.name }}</h3>
                <p>价格: {{ order.price }}</p>
                <button onclick="deleteOrderedMenu({{ order.order_id }})">删除</button>
            </div>
            {% endfor %}
        </div>
        
        <script src="{{ url_for('static', filename='scripts.js') }}"></script>
        <script>
            // 删除已点餐项
            function deleteOrderedMenu(orderId) {
                if (confirm('确定要删除此已点餐项吗？')) {
                    fetch('/delete_ordered_menu/' + orderId, {
                        method: 'POST',
                    })
                    .then(response => response.json())
                    .then(data => {
                        if (data.status === 'success') {
                            showToast('删除成功！');
                            window.location.reload();  // 重新加载页面
                        } else {
                            alert('删除已点餐项失败，请重试。');
                        }
                    })
                    .catch(error => {
                        console.error('Error deleting ordered menu:', error);
                        alert('删除已点餐项失败，请重试。');
                    });
                }
            }
            updateOrderedMenus();
        </script>
    </div>
    <footer>
        <nav>
            <a href="/">首页</a>
            <a href="/ordered_menus">已点餐</a>
        </nav>
    </footer>
</body>
</html>